<?php
include('auth.php');
//this file process all the books 
//the following code includes the mysql connect code
include 'connect.php';

function mysql_insert($table, $inserts) {
    $values = array_map('mysql_real_escape_string', array_values($inserts));
    $keys = array_keys($inserts);
       
    return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
}

// this code looks for all POST vars 
$bookname = $_GET['bookname'];
$authlast = $_GET['authlast'];
$authfirst = $_GET['authfirst'];
$publisher = $_GET['publisher'];
$yearpub = $_GET['yearpub'];
$edition = $_GET['edition'];
$call = $_GET['call'];
$fiction = $_GET['fiction'];
$inhouse = $_GET['inhouse'];
$isbn = $_GET['isbn'];
$media_type = $_GET['media'];
$stamp = time();


mysql_insert('books', array(
    'name' => $bookname,
    'author' => $authfirst,
    'author_last' => $authlast,
	'publisher' => $publisher,
	'year_pub' => $yearpub,
	'edition' => $edition,
	'callnum' => $call,
	'fiction' => $fiction,
	'in_house' => $inhouse,
	'timestamp' => $stamp,
	'isbn' => $isbn,
	'media_type' => $mediatype,
	'checkout' => 'false',
));

$sql_select = "SELECT * FROM books WHERE timestamp = '$stamp'";
$fetch = mysql_query($sql_select);
$book_fetch = mysql_fetch_array($fetch);
$name = $book_fetch['name'];
$barcode = $book_fetch['barcode'];
$author_first = $book_fetch['author'];
$author_last = $book_fetch['author_last'];
$call = $book_fetch['callnum'];
header("Location: /olms/?p=bookman/addbook.php&status=added&barcode=$barcode&callnum=$call");
?>